import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {TipService} from "../../../services/tip.service";
import {ExtendHttpService} from "../../../../common/extend-http.service";
import {EssService} from "../../ess.service";

@Component({
  selector: 'app-outbound-log',
  templateUrl: './outbound-log.component.html',
  styleUrls: ['./outbound-log.component.css']
})
export class OutboundLogComponent implements OnInit {

  isLoading = false;
  loading = true;
  isFlag = false;
  tipType = 'error';
  totalPage = 1;
  loadMoreFlag = true;
  list = [];
  params = {start: 1, key: '', startTime: '', endTime: ''};

  constructor(
    private ext: ExtendHttpService,
    public ess: EssService,
    private router: Router,
    private route: ActivatedRoute,
    private tips: TipService
  ) { }

  ngOnInit() {
    this.getData(true);
  }

  getData(searchFlag?: boolean) {
    this.params.start = this.params.start > 1 ? this.params.start + 1 : 1;
    this.ext.post('/merchantApp/inventory/stock/findOutStock', this.params).subscribe(response => {
      let data = response.json();
      if (data.code === '0') {
        this.list = data.page.list;
        this.params.start = data.page.pageNumber;
        this.totalPage = data.page.totalPage;
        this.loading = false;
      } else {
        this.tipType = 'error';
        this.loading = false;
        this.tips.change(true, this.ess.errTips(data));
      }
    }, error => {
      this.tipType = 'error';
      this.loading = false;
      this.tips.change(true, '系统繁忙，操作失败！');
    });
  }

}
